package com.wnxy.controller;


import com.wnxy.annotation.Validate;
import com.wnxy.dto.*;
import com.wnxy.model.Perform;
import com.wnxy.service.PerformService;
import com.wnxy.util.BeanCopyUtil;
import com.wnxy.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author alice
 * @since 2021-10-25
 */
@RestController
@RequestMapping("/perform")
public class PerformController {
    @Autowired
    private PerformService PerformService;
//    @Validate
    @PostMapping("/save")
    public Result savePerform(@RequestBody SavePerformVo updatePerformVo) throws ParseException {
        Perform perform = BeanCopyUtil.copyProperties(updatePerformVo, Perform.class);
        PerformDto performDto = PerformService.savePerform(perform);
        return  Result.getInstance().setFlag(true).setStatusCode(StatusCode.SUCCESS.getCode())
                .setMessage("保存成功").setData(performDto);
    }
//    @Validate
    //分页查询演出信息
    @PostMapping("/pageQuery")
    public Result pageQuery(@RequestBody QueryPageVo pageVo){
        PageDto pageDto = PerformService.pageQuery(pageVo);
        return Result.getInstance().setFlag(true).setStatusCode(StatusCode.SUCCESS.getCode())
                .setMessage("查询成功").setData(pageDto);
    }
//    @Validate
    //删除演出信息
    @PostMapping("/del")
    public Result delData(@RequestBody DeleteIdsVo deleteIdsVo){
        DeleteDto deleteDto = PerformService.delPerformByIds(deleteIdsVo.getIds());
        return Result.getInstance().setFlag(true).setStatusCode(StatusCode.SUCCESS.getCode())
                .setMessage("删除成功").setData(deleteDto);
    }
//    @Validate
    //发布演出信息
    @PostMapping("/up")
    public Result upPerform(@RequestBody UpPerformVo upPerformVo) throws ParseException, IllegalAccessException {
        System.out.println(upPerformVo);
        TicketsDto ticketsDto = PerformService.upPerform(upPerformVo);
        return Result.getInstance().setFlag(true).setStatusCode(StatusCode.SUCCESS.getCode())
                .setMessage("发布成功").setData(ticketsDto);
    }
    @GetMapping("/plan/{performRoomId}")
    public Result loadPlan(@PathVariable("performRoomId")Integer performRoomId){
        List<PlanDto> planDtos = PerformService.loadPlan(performRoomId);
        return Result.getInstance().setFlag(true).setStatusCode(StatusCode.SUCCESS.getCode())
                .setMessage("查询成功").setData(planDtos);
    }
}

